import requests
import json
from 取号记录数据生成表格 import 数据写入
with open('cookie.txt', 'r', encoding='utf-8') as f:
    headers = json.load(f)
url = "http://59.215.208.54:91/sysaction.do"
region_code = {
    "遵义市": "520300",
    "红花岗区": "520302",
    "汇川区": "520303",
    "桐梓县": "520322",
    "绥阳县": "520323",
    "正安县": "520324",
    "道真县": "520325",
    "务川县": "520326",
    "凤冈县": "520327",
    "湄潭县": "520328",
    "余庆县": "520329",
    "习水县": "520330",
    "赤水市": "520381",
    "新蒲新区": "520383"
}
for k, v in region_code.items():
    params = {
        'ClassName': 'com.hyysoft.smart.action.call.CallGetNumRecAction.GetCallNumRecList',
        'DB_Conn': 'SMARTJH',
        'hall_id': v,
        'getnum_time': '2025-10-01~2025-10-31',
        'date_query': 'getnum_time',
        'page': '1'
    }

    try:
        response = requests.get(url, params=params,headers=headers,timeout=500)
        response.raise_for_status()  # 如果响应状态码不是200，引发HTTPError异常
        data = response.json()
        # formatted_data = json.dumps(data, indent=4, ensure_ascii=False)
        # print(formatted_data)


        数据写入(data['data'], k)
        # print(data)
    except Exception as e:
        print(k+"异常")
        print(e)
